
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<jsp:include page="../Common/header.jsp"></jsp:include>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
	<section class="content-header">
		<h1>权限分配</h1>
		<ol class="breadcrumb">
			<li><a href="<c:url value="/Admin/index" />"><i
					class="fa fa-dashboard"></i> Home</a></li>

			<c:forEach items="${routers}" var="router">
				<li><i class="${router.icon}"></i><a href="javascript:void(0)">&nbsp&nbsp${router.name
						}</a></li>
			</c:forEach>

		</ol>
	</section>

	<section class="content">
		<style>
.sub_left_menu {
	height: 650px;
	overflow-y: scroll;
}
</style>
		<div class="page-header clearfix">
			<h1 class="col-sm-8"></h1>
			<div class="col-sm-4">
				<form  id="form_search" method="post" action="<c:url value="/Role/user" />"
					class="pull-right">
					<div class="input-group col-20">
						<input class="form-control" type="text" name="keyword"
							id="keyword">
						<div class="input-group-btn">
							<a class="btn btn-m btn-primary" onclick="submit_search();"><i
								class="fa fa-search"></i></a>
						</div>
					</div>
				</form>
			</div>
		</div>
		<div class="operate panel panel-default">
			<div class="panel-body">
				<div class="pull-right">
					<a onclick="save()" class="btn btn-sm btn-primary">保存</a>
				</div>
			</div>
		</div>
		<!-- 列表显示区域  -->
		<div class="box box-danger">
			<div class="box-header with-border">
				<h3 class="box-title"></h3>

				<div class="box-tools pull-right">
					<button type="button" class="btn btn-box-tool"
						data-widget="collapse">
						<i class="fa fa-minus"></i>
					</button>
					<button type="button" class="btn btn-box-tool" data-widget="remove">
						<i class="fa fa-remove"></i>
					</button>
				</div>
			</div>
			<div class="box-body">
				<div class="row">
					<form id="setRoleForm" action="<c:url value="/Role/setRole" />" method="post">
						<div class="col-sm-8 sub_left_menu">
							<table class="table table-bordered" id="usersTable">
								<thead>
									<tr>
										<th class="text-center col-4"><label
											class="inline pull-left"> <input class="ace"
												type="checkbox" name="id-toggle-all" id="id-toggle-all">
												<span class="lbl"></span></label></th>
										<th><nobr> 员工编号 </nobr></th>
										<th><nobr> 姓名 </nobr></th>
										<th><nobr> 部门 </nobr></th>
										<th><nobr> 职位 </nobr></th>
										<th><nobr> 状态 </nobr></th>
									</tr>
								</thead>
								<tbody  class="tbody">
								<c:forEach items="${users}" var="user">
									<tr id="${user.id }">
										<td class="text-center col-3"><label
											class="inline pull-left"> <input class="ace"
												type="checkbox" name="user_id" value="${user.id }" /> <span
												class="lbl"></span></label></td>
										<td><nobr> ${user.accountName } </nobr></td>
										<td><nobr> ${user.name } </nobr></td>
										<td><nobr> ${user.dept.name } </nobr></td>

										<td><nobr> ${user.position.name } </nobr></td>
										<td><nobr>${user.status eq true?'启动':'禁用'} </nobr></td>
									</tr>
									</c:forEach>
								</tbody>
							</table>
						</div>
						<div class="col-sm-4 sub_content">
							<input type="hidden" name="id" id="id"> <input
								type="hidden" name="pid" id="pid" value=""> <input
								type="hidden" name="ajax" id="ajax" value="0"> <input
								type="hidden" name="opmode" id="opmode" value="">
							<table class="table table-bordered" id="rolesTable">
								<thead>
									<tr>
										<th>&nbsp;</th>
										<th>名称</th>
									</tr>
								</thead>
								<tbody>
								
								<c:forEach items="${roles }" var="role">
								
									<tr id="role_${role.id}">
										<td class="col-4"><label class="inline pull-left ">
												<input class="ace" type="checkbox" 
												name="role_list" value="${role.id}"> <span class="lbl"></span>
										</label></td>
										<td>${role.name}</td>
									</tr>
									</c:forEach>
								</tbody>
							</table>
						</div>
					</form>
				</div>
			</div>
		</div>
	</section>

</div>
<!-- /.content-wrapper -->
<jsp:include page="../Common/footer.jsp"></jsp:include>
<script type="text/javascript">

$.ajaxSetup({   
    contentType:"application/x-www-form-urlencoded;charset=utf-8",   
    complete:function(XMLHttpRequest,textStatus){ 
      var sessionstatus=XMLHttpRequest.getResponseHeader("sessionstatus"); //通过XMLHttpRequest取得响应头，sessionstatus，  
          if(sessionstatus=="timeout"){ 
              alert("登录超时,请重新登录！");
          //如果超时就处理 ，指定要跳转的页面  
            window.location.reload();   
          }   
       }   
  }); 

$("#usersTable tbody tr").click(function() {
	$("#usersTable tbody tr").attr("class", "");
	$(this).attr("class", "active");
	$("#rolesTable tbody td input").prop("checked",false);
	 $.post("<c:url value='/Role/getRolesByUserId' />", {
		id : $(this).attr("id"),
	}, function(data, status) {
		
		 
		
		if (data == "" || data == null)
			return;
		data = eval(data);
		
		 $(data).each(function(){
			    $("#role_"+$(this)[0].id+" td input").prop("checked","checked");
			  });

	}); 

});

function save(){
	if ($("input:checked[name='user_id']").length < 1) {
		alert("请选择用户");
		return false;
	};
	if ($("input:checked[name='role_list']").length < 1) {
		alert("请选择权限");
		return false;
	};
	$("#setRoleForm").submit();
}

function submit_search(){
	
	$("#form_search").submit();
}
	
	
</script>
